package com.code;

import java.util.ArrayList;
import java.util.List;

import com.example.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class Chart_ChooseType extends Activity {

	private Spinner spChart;
	private Button btViewChart;
	private final int REQUESTCODE_CHART_CALL_MONTH_IN_YEAR = 100;
	private final int REQUESTCODE_CHART_DOANHTHU = 101;
	private final int REQUESTCODE_CHART_DOANHTHUTHANG = 102;
	private final int REQUESTCODE_CHART_DOANHTHUTUAN = 103;
	private final int REQUESTCODE_CHART_CHONKHO = 104;
	private final int REQUESTCODE_CHART_DOANHTHUQUI = 105;
	private static EditText etChonKho;
	private String strKhoChon = "";

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == REQUESTCODE_CHART_CHONKHO) {		
			// get User
			if (resultCode == RESULT_OK) {
				strKhoChon = data.getStringExtra("strListKho");
				etChonKho.setText(data.getStringExtra("strListKho").toString());
			} else if (resultCode == RESULT_CANCELED) {
			}
		}
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bd_chonmau);

		// declare variable
		spChart = (Spinner) findViewById(R.id.spChart);
		btViewChart = (Button) findViewById(R.id.btViewChart);
		etChonKho = (EditText) findViewById(R.id.etChonKhoChart);

		// load spinner spbieudo
		List<String> listMau = new ArrayList<String>();
		listMau.add(0, "Cuộc gọi trong năm");
		listMau.add(1, "Doanh thu trong ngày");
		listMau.add(2, "Doanh thu theo tuần");
		listMau.add(3, "Doanh thu theo tháng");
		listMau.add(4, "Doanh thu theo quí");
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_dropdown_item, listMau);
		spChart.setAdapter(adapter);

		// set button xembd click
		btViewChart.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				if (spChart.getSelectedItemPosition() == 0) {
					Intent i = new Chart_Call_MonthInYear()
							.execute(Chart_ChooseType.this);
					startActivityForResult(i,
							REQUESTCODE_CHART_CALL_MONTH_IN_YEAR);
 				} else if (spChart.getSelectedItemPosition() == 1) {
					Intent i = new Intent(Chart_ChooseType.this, Chart_DoanhThu.class);
					startActivityForResult(i, REQUESTCODE_CHART_DOANHTHU);
				} else if (spChart.getSelectedItemPosition() == 3) {
					Intent i = new Chart_DoanhThuThang()
					.execute(Chart_ChooseType.this,strKhoChon);
			startActivityForResult(i, REQUESTCODE_CHART_DOANHTHUTHANG);
				} else if (spChart.getSelectedItemPosition() == 2) {
					Intent i = new  Chart_DoanhThuTuan() 
							.execute(Chart_ChooseType.this,strKhoChon);					 
					startActivityForResult(i, REQUESTCODE_CHART_DOANHTHUTUAN);
				}
				 else if (spChart.getSelectedItemPosition() == 4) {
						Intent i = new  Chart_DoanhTheoQui() 
								.execute(Chart_ChooseType.this,strKhoChon);					 
						startActivityForResult(i, REQUESTCODE_CHART_DOANHTHUQUI);
					}
			}
		});
		
		etChonKho.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(Chart_ChooseType.this,
						TK_ChonKho .class), REQUESTCODE_CHART_CHONKHO);
			}
		});

	}

}
